import QtQuick 2.15
import QtQuick.Controls 2.15
import RadioGlobal 1.0 as RadioGlobal
import "./../../Control/RadioJs.js" as RadioJs
Item {
    id: footItem

    Column{
        id: rootLayout
        anchors.fill: parent
        spacing: 10
        clip: true

        //FreqPage 界面
        Rectangle{
            id:freqShow
            width: parent.width
            height: parent.height * 0.9
            Text{
                id: freqText
                anchors.centerIn: parent
                text: RadioGlobal.RadioData.historyChannelModel.get(RadioGlobal.RadioData.historyChannelCurrentIndex ) !== undefined
                      ? "频率显示: " + RadioGlobal.RadioData.historyChannelModel.get(RadioGlobal.RadioData.historyChannelCurrentIndex ).freq
                      : ""

            }
        }

        Item{

            id: buttonGroupItem
            width: parent.width
            height: 20
            Row {
                id: buttonGroupLayout
                anchors.fill: parent
                spacing: 10
                //占位符
                Item {
                    id: left
                    width: parent.width * 0.4
                    height: parent.height
                }

                Button{
                    id:btnPrev
                    text: "prev"
                    width: parent.width * 0.1
                    height: parent.height
                    onClicked: {
                        if( RadioGlobal.RadioData.historyChannelCurrentIndex <= 0 )
                            return
                        RadioGlobal.RadioData.historyChannelCurrentIndex -= 1
                        //播放频道
                        RadioJs.playChannel( RadioGlobal.RadioData.historyChannelModel.get( RadioGlobal.RadioData.historyChannelCurrentIndex ).freq )
                    }
                }

                Repeater {
                    width: parent.width * 0.1
                    model: RadioGlobal.RadioData.historyChannelModel
                    delegate: Rectangle {
                        id: delegateItem
                        width: 20
                        height: parent.height
                        color: RadioGlobal.RadioData.historyChannelCurrentIndex === index ? "red" : "white"
                        radius: 5
                        border.color: "black"
                        border.width: 1
                        Text {
                            id: idxText
                            anchors.centerIn: parent
                            text: index + 1
                        }
                    }
                }



                Button{
                    id:btnNext
                    text: "next"
                    width: parent.width * 0.1
                    height: parent.height
                    onClicked: {
                        if( RadioGlobal.RadioData.historyChannelCurrentIndex >= RadioGlobal.RadioData.historyChannelTotalIndex - 1 )
                            return
                        RadioGlobal.RadioData.historyChannelCurrentIndex += 1
                        //播放频道
                        RadioJs.playChannel( RadioGlobal.RadioData.historyChannelModel.get( RadioGlobal.RadioData.historyChannelCurrentIndex ).freq )
                    }
                }

                //占位符
                Item {
                    id: right
                    width: parent.width * 0.4
                    height: parent.height
                }
            }
        }
    }

    //初始化
    Component.onCompleted: {
        RadioJs.loadHistoryChannel()
    }



}
